$(function () {
    $("#wlck").hide()
    $(".cpwlmx").hide()
    $("#aaa").hide()

    $("#sjdcx").bootstrapTable({
        method: "post",
        contentType: 'application/json',
        url: "/gxwl/gxwlsjdcx",
        striped: true,
        pageNumber: 1,
        pagination: true,
        sidePagination: 'server',
        pageSize: 3,
        pageList: [2,3,5,6],
        queryParams: function (parmes) {
            return {
                pageNum: (parmes.offset / parmes.limit) + 1,
                pageSize: parmes.limit,
                registerTime:$("#registerTime").val(),
                checker:$("#checked").val(),
            }
        },
        columns: [
            {title: "工序设计单号", field: "designId", align: 'center'},
            {title: "产品编号", field: "productId", align: 'center'},
            {title: "产品名称", field: "productName", align: 'center'},
            {title: "设计单状态", field: "designModuleTag", align: 'center',
                formatter:function (value, row, index) {
                    if (value==2){
                        return "执行";
                    }else {
                        return  "等待";
                    }
                }
            },
            {title: "审核状态", field: "designModuleTag", align: 'center',
                formatter: function (value, row, index) {
                    if (value==2){
                        return "<font color=\"green\">通过审核</font>";
                    }else {
                        return  "<font color=\"orange\">等待审核</font>";
                    }
                }
            },
            {title: "查看", field: "designId", align: 'center',
            formatter:function(value,row,index){
                let  a="<button onclick='ckyx("+row.id+")' class=\"btn btn-primary\" >查看</button>"
                return a
            }
            }
        ]
    })
})

function kscx() {
    $("#sjdcx").bootstrapTable("refresh")
}

function ckyx(a) {
    $("#wlck").show()
    $("#div1").hide()
    $("#aaa").show()


    $.ajax({
        type:"post",
        contentType:"application/json;charset:utf-8",
        url:"/gxwl/cxck/"+a,
        dataType:"json",
        async:true,
        success:function (data) {
            $("#gxdbh").html(data.designId);
            $("#sjr").html(data.designer);
            $("#name").html(data.productName);
            $("#id").html(data.productId);
            $("#zcb").html(data.costPriceSum);
            $("#yq").html(data.procedureDescribe);
            $("#shr").html(data.checker);
            $("#shtime").html(data.checkTime);
        }
    })
    $.ajax({
        type:"post",
        contentType:"application/json;charset:utf-8",
        url:"/gxwl/cxckx/"+a,
        dataType:"json",
        async:true,
        success:function (data) {
        let tab=document.getElementById("wlsjmx");
        tab.innerHTML="";
        for (let i=0;i<data.length;i++){
            let totalPrice=data[i].moduleSubtotal;
            if (totalPrice==undefined){
                totalPrice="";
            }
                tab.innerHTML+="<tr><td>"+data[i].detailsNumber+"</td><td>"+data[i].procedureName+"</td><td>"+data[i].procedureId+"</td>" +
                    "<td>"+data[i].labourHourAmount+"</td><td>"+data[i].subtotal+"</td><td>"+totalPrice+"</td>" +
                    "<td><a href='#' onclick='slectck("+data[i].id+")' class=\"btn btn-primary\">查看</a></td></tr>";
        }
        }
        })


}
function slectck(a) {

    $("#wlck").hide()
    $("#div1").hide()


    $.ajax({
        type:"post",
        contentType:"application/json;charset:utf-8",
        url:"/gxwl/ckxwy/"+a,
        dataType:"json",
        async:true,
        success:function (data) {
            if (data==""){
                alert("该工序未进行物料设计")
                $(".cpwlmx").hide()
                $("#wlck").show()
            }else {
                $(".cpwlmx").show()

                let a= document.getElementById("tabsj")
                a.innerHTML="";
                for (i=0;i<data.length;i++){
                    a.innerHTML+="<tr><td>"+data[i].detailsNumber+"</td><td>"+data[i].productName+"</td><td>"+data[i].productId+"</td>" +
                        "<td>"+data[i].productDescribe+"</td><td>"+data[i].amount+"</td><td>"+data[i].amountUnit+"</td><td>"+data[i].costPrice+"</td>" +
                        "<td>"+data[i].subtotal+"</td></tr>"
                }
            }


        }
    })
}
function fhan() {
    $(".cpwlmx").hide()
    $("#wlck").show()
    $("#div1").hide()

}

function jxfh() {
    $(".cpwlmx").hide()
    $("#wlck").hide()
    $("#div1").show()
    $("#aaa").hide()
}